#	$Id$
#
# Build definitions for Canopy modules
#
# This make include file is loosely inspired from the standard include files
# found in /usr/share/mk.

.if exists(${.CURDIR}/../Makefile.inc)
.include "${.CURDIR}/../Makefile.inc"
.endif

RM?=		rm -f

MODROOT=	${.CURDIR}/../../share/misc/root.c

OBJS?=		${SRCS:N*.h:R:S/$/.o/g}
MOD_NAME?=	${.CURDIR:C/.*\///}
MODEXT?=	.so
MODFILE?=	${MOD_NAME}${MODEXT}
MODCFLAGS?=	-DPIC -fPIC
MODLDFLAGS?=	-shared


MODDEFS=	-DMOD_NAME="${MOD_NAME}" -DMOD_AUTHOR="${MOD_AUTHOR}" \
		-DMOD_DESCR="${MOD_DESCR}"


CFLAGS+=	${MODCFLAGS}
LDFLAGS+=	${MODLDFLAGS}

.if defined(VERSION_MAJOR)
CFLAGS+=	-DVERSION_MAJOR=${VERSION_MAJOR}
.endif
.if defined(VERSION_MINOR)
CFLAGS+=	-DVERSION_MINOR=${VERSION_MINOR}
.endif


.MAIN: all

all: ${MODFILE}


checkinfo:
	@if [ x${MOD_NAME} = x ]; then					\
		echo "You need to specify a module name in MOD_NAME";	\
		exit 1;							\
	fi
	@if [ "x${MOD_AUTHOR}" = "x" ]; then				  \
		echo "You need to specify a module author in MOD_AUTHOR"; \
		exit 1;							  \
	fi

roots.c: checkinfo
	@echo "Generating module root code for ${MOD_NAME}"
	sed -e 's/@MOD_NAME@/${MOD_NAME}/' -e 's/@MOD_AUTHOR@/${MOD_AUTHOR}/' \
	    -e 's/@MOD_DESC@/${MOD_DESC}/' ${MODROOT} > roots.c


${MODFILE}: roots.o ${OBJS}
	${LD} ${LDADD} ${LDFLAGS} ${PICFLAGS} -o ${MODFILE} ${OBJS} roots.o
	${RM} roots.c

${MOD_NAME}: ${MODFILE}

clean:
	${RM} ${OBJS} roots.* ${MODFILE}

cleandir: clean
	${RM} .depend

install: ${MODFILE}
	${INSTALL} -o ${MODOWN} -g ${MODGRP} -m ${MODMODE} \
	    ${MODFILE} ${DESTDIR}${MODDIR}

.include "dep.mk"
